package managesystem;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class deleteAidToolServlet extends HttpServlet {

        private static final long serialVersionUID = 1L;
        
        /**
         * Afhandelen van de informatie van het formulier
         */
        public void doPost(HttpServletRequest req, HttpServletResponse resp) {
                HttpSession session = req.getSession();
                Student currStud = (Student) session.getAttribute("currStud");
                String aidTool = req.getParameter("delAidTool");
                if(aidTool != null){
                	boolean deleted = currStud.deleteAidTool(aidTool);
                	if(deleted == true){
                        session.setAttribute("message", "This aidtool "+ aidTool +" has been deleted succesfully.");
                	}
                	else{
                        session.setAttribute("error", "This aidtool "+ aidTool +" can not be deleted.");
                	}
                }
                else{
                	session.setAttribute("error", "You did not select an aidtool.");
                }
                session.setAttribute("currStud", currStud);
                try {
                        resp.sendRedirect("/index.jsp?id=dashboard");
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
}
